<?php
/**
 * Created by PhpStorm.
 * User: cephei
 * Date: 12/12/15
 * Time: 3:04 PM
 */
namespace Plugins\User;

use Core\PluginContainer;

class Plugin_User{

    private $db;

    public function __construct()
    {
        $this->db = PluginContainer::getInstance()->singletonMake('database');
    }

    public function registerUser($userName,$passWord,$mail,$qq,$weChat,$level){
        if(empty($this->db->first("select * from plg_user where username='$userName'"))){
            $this->db->insert("plg_user",["username"=>$userName,"password"=>$passWord,"mail"=>$mail,"qq"=>$qq,"wechat"=>$weChat,"level"=>$level]);
        }
    }

    public function getUserInfoById($userId){
        return $this->db->first("select * from plg_user where id=$userId");
    }

    public function selectUserByLevel($level){
        return $this->db->get("select * from plg_user where level>=$level");
    }

    public function getUserInfo($userName,$passWord){
        return $this->db->first("select * from plg_user where username='$userName' and password='$passWord'");
    }
}
